package com.situ.ssm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.object.UpdatableSqlQuery;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.situ.ssm.entity.User;
import com.situ.ssm.service.IUserService;
import com.situ.ssm.service.impl.UserServiceImpl;

// 相当于原来的Servlet
@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private IUserService userService;

	// http://localhost:8080/SSM1907/user/getUserListPage.action
	@RequestMapping("/getUserListPage")
	public String getUserListPage(Model model) {
		List<User> list = userService.list();
		model.addAttribute("list", list);
		// req.getRequestDispatcher("/WEB-INF/jsp/user_list.jsp").forward();
		// 转发
		// return "/WEB-INF/jsp/user_list.jsp";
		return "user_list";
	}
	
	// /user/deleteById.action?id=23
	@RequestMapping("/deleteById")
	public String deleteById(Integer id) {
		System.out.println(id);
		int count = userService.deleteById(id);
		
		return "redirect:/user/getUserListPage.action";
	}
	
	@RequestMapping("/getUserAddPage")
	public String getUserAddPage() {
		return "user_add";
	}
	
	@RequestMapping("/add")
	public String add(User user) {
		System.out.println(user);
		int count = userService.add(user);
		return "redirect:/user/getUserListPage.action";
	}
	
}
